import os
import pyautogui
from pynput.keyboard import Key, Controller
from find import remove_mouse,find_colorimage,find_image_on_screen,find_dark
from set import notice
import time
import subprocess

# 进入界面
def daily_task():
    #点击图标
    remove_mouse('image/logo.bmp',10)


    time.sleep(8)
    remove_mouse('image/start_game.bmp', 10)

    time.sleep(5)
    find_colorimage('image/agree.bmp', 5)

    time.sleep(3)
    remove_mouse('image/return.bmp', 10)#返回

#执行日常任务
def daily_task_get():#收尾，领取宝箱，奖励等
    time.sleep(5)
    remove_mouse('image/grow.bmp', 10)#点击成长
    time.sleep(5)
    while find_dark('image/linqu.bmp')==True:#点击领取
        remove_mouse('image/linqu.bmp', 10)
        time.sleep(2)
        if find_colorimage('image/linqu.bmp', 5,False)==False:
           break
    remove_mouse('image/baoxiang1.bmp', 10)
    remove_mouse('image/baoxiang2.bmp', 10)
    remove_mouse('image/baoxiang3.bmp', 10)
    remove_mouse('image/baoxiang5.bmp', 10)#先点击宝箱5，防止挡住宝箱4
    remove_mouse('image/baoxiang4.bmp', 10)
    remove_mouse('image/baoxiang6.bmp', 10)
    print("宝箱领取完成")
    remove_mouse('image/return.bmp', 10)  # 返回主界面

def fight(peroid):#循环刷演练场，假定10次
    time.sleep(5)
    remove_mouse('image/fight.bmp', 10)#点击演练场
    for i in range(peroid):
        remove_mouse('image/start_fight.bmp', 10)
        time.sleep(10)
        if find_colorimage('image/master.bmp', 5,False)==True:  #主公模式
           print("主公模式")
           remove_mouse('image/bei.bmp', 10)#选择刘备
           remove_mouse('image/bei.bmp', 10)
        else:
            while find_dark('image/yes.bmp')==False:
                if find_dark('image/yes.bmp') or find_dark('image/plus.bmp')==True:
                    break
                else:
                    x,y=find_image_on_screen('image/person1.bmp')
                    pyautogui.moveTo(x, y)
                    pyautogui.moveRel(-25, 400)
                    time.sleep(1)
                    pyautogui.click()
                    continue
        remove_mouse('image/yes.bmp', 10)#确认
        remove_mouse('image/plus.bmp', 10)#点击加号
        remove_mouse('image/return1.bmp', 10)#返回
        remove_mouse('image/yes2.bmp', 10)  #确定

def daily_task_start(answer,yuanbao):#开始执行日常任务
    time.sleep(5)
    remove_mouse('image/grow.bmp', 10)  # 点击成长
    time.sleep(5)
    #执行那年今日
    if answer==True:
        find_colorimage('image/answer.bmp', 10,True)
        time.sleep(3)
        #鼠标下移动30px
        pyautogui.moveRel(0, 30)
        pyautogui.click()
        # 开始回答问题
        remove_mouse('image/A.bmp', 10)
        remove_mouse('image/B.bmp', 10)
        time.sleep(5)
        # 第二问
        remove_mouse('image/A.bmp', 10)
        remove_mouse('image/B.bmp', 10)
     # 执行摘元宝
    if yuanbao==True:
        time.sleep(3)
        remove_mouse('image/want.bmp', 10) #点击我要奖励
        time.sleep(3)
        find_colorimage('image/tree.bmp', 10, True)
        pyautogui.moveRel(900, 0)
        pyautogui.click()#点击前往
        time.sleep(3)
        #点击浇水
        remove_mouse('image/water.bmp', 10)
        time.sleep(3)
        if find_dark('image/yuan.bmp')==True:
            remove_mouse('image/yuan.bmp', 10)
        elif find_dark('image/done.bmp')==True:
            print("已经摘完了元宝")
            remove_mouse('image/return.bmp', 10)  # 返回次级界面
            remove_mouse('image/return.bmp', 10)  # 返回主界面
def tehui(): #执行签到活动
    time.sleep(3)
    remove_mouse('image/tehui.bmp', 10)
    time.sleep(3)
    while find_dark('image/get.bmp')==True:
        remove_mouse('image/get.bmp', 10)
        if find_dark('image/get.bmp')==False:
            break
    remove_mouse('image/return.bmp', 10)  # 返回主界面
def quit(reson):
    subprocess.call(['taskkill', '/F', '/IM', os.path.basename("D:\模拟器\LDPlayer4\dnplayer.exe")])
    notice(reson)


